package com.dlmz.view;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.dlmz.model.Statistics;
import com.dlmz.util.BaseDao;
import com.dlmz.util.ResultsetToStatistic;


@SuppressWarnings("serial")
public class StatisticsModel extends AbstractTableModel{  
    @SuppressWarnings("rawtypes")
	private Vector columnNames;  
    @SuppressWarnings("rawtypes")
	private Vector rowDates;  
    //========查询学生  
    @SuppressWarnings({ "unchecked", "rawtypes" })
	public void queryStatistic(String sql,Object...objects)  
    {  
        BaseDao baseDao = null;  
        //========初始化JTable信息  
        columnNames = new Vector();  
        rowDates = new Vector();  
        columnNames.add("学号"); columnNames.add("姓名");  
        columnNames.add("系别"); columnNames.add("班级");  
        columnNames.add("联系方式"); columnNames.add("身高");  
        columnNames.add("胸围");columnNames.add("血压"); 
        columnNames.add("沙眼"); columnNames.add("病史");
        columnNames.add("健康情况");
        try {  
            baseDao = new BaseDao();  
            List list= baseDao.query(sql, new ResultsetToStatistic(),objects);  
            if (list.size()>0) {
            	for (int i = 0; i < list.size(); i++) {
    				Statistics statistics=(Statistics) list.get(i);
    				//System.out.println(student.toString());
    				Vector row = new Vector(); 
                    row.add(statistics.getSno());  
                    row.add(statistics.getSname());  
                    row.add(statistics.getSdept());  
                    row.add(statistics.getSclass());  
                    row.add(statistics.getSphone());  
                    row.add(statistics.getSheight()); 
                    row.add(statistics.getChest());
                    row.add(statistics.getbPressure());
                    row.add(statistics.getTracmStr());
                    row.add(statistics.getMedicalhistory());
                    row.add(statistics.getPresult());
                    rowDates.add(row);
    			}
    		}	 
        } catch (Exception e) {  
            // TODO: handle exception  
        }   
    }  
  
    public int getColumnCount() {  
  //告知列数，用标题数组的大小,这样表格就是rowData.size()行，columnNames.size()列了  
        return this.columnNames.size();  
    }  
  
    public int getRowCount() {   
        return this.rowDates.size(); 
        //这里是告知表格应该有多少行，我们返回rowDatas上的String数组个数
    }  
  
    @SuppressWarnings("rawtypes")
	public Object getValueAt(int row, int col) {  
        // TODO Auto-generated method stub  
        if(!rowDates.isEmpty())  
            return ((Vector)this.rowDates.get(row)).get(col);  
        else  
            return null;  
    }  
    @Override  
    public String getColumnName(int column) {  
        return (String)this.columnNames.get(column);  
      //这里是告知表格各列的列名，我们返回该列的列名
    }    
}  
